package example

import (
	"database/sql"
	"fmt"
	"game/game-db/mysql/dao"
	"game/game-db/orm/metag"
	"math/rand"
)

type ExampleIdentityEntity struct {
	ExampleParent
	id   string `orm:"id=IDENTITY;name=id;comment=唯一ID"`
	name string `orm:"comment=名字;length=255"`
	num  int64  `orm:"comment=学号"`
	has  bool   `orm:"comment=是否有"`
}

func (t *ExampleIdentityEntity) TableMetag() metag.TableMetag {
	tableTag := metag.TableMetag{
		Name:    "example_identity_entity",
		Comment: "例子",
		Indexes: make([]*metag.IndexMetag, 0),
	}
	return tableTag
}

func (t *ExampleIdentityEntity) Id() string {
	return t.id
}
func (t *ExampleIdentityEntity) SetId(id string) {
	t.id = id
}
func (t *ExampleIdentityEntity) SetName(name string) {
	t.name = name
}
func (t *ExampleIdentityEntity) SetNum(num int64) {
	t.num = num
}
func (t *ExampleIdentityEntity) SetHas(has bool) {
	t.has = has
}
func (t *ExampleIdentityEntity) SetSomeInfo(someinfo string) {
	t.someinfo = someinfo
}

func TestExampleIdentityEntity(sqlDB *sql.DB) {
	iidao := dao.NewDefaultBaseDao[*ExampleIdentityEntity](sqlDB, &ExampleIdentityEntity{})
	fmt.Println(iidao.Sql(&ExampleIdentityEntity{}))

	var entity ExampleIdentityEntity
	entity.SetId(fmt.Sprintf("AAAA%v", rand.Int63n(9885454445465)))
	// entity.SetName("AAAA")
	entity.SetNum(9875451)
	entity.SetHas(true)
	entity.SetSomeInfo("skdjal4w5e4")
	iidao.Insert(&entity)

	entity.SetSomeInfo("PPPPPP")
	iidao.Update(&entity)

	fmt.Println(entity.Id())
}
